package com.rran.study.designpattern.behavioral.observer.factory;

import com.rran.study.designpattern.behavioral.observer.enums.ListenerEnums;
import com.rran.study.designpattern.behavioral.observer.listener.app.AppListener;

/**
 * @author yy
 * @Type ListenerEnumFactory.java
 * @Desc
 * @date 2020/7/21 22:07
 */
public class ListenerEnumFactory {


    /**
     * 反射实体化具体的处理者
     *
     * @param listenerEnum
     * @return
     */
    public static AppListener getAppListener(ListenerEnums listenerEnum) {
        try {
            String classPath = listenerEnum.getClassPath();
            Class<?> clazz = Class.forName(classPath);
            AppListener listener = (AppListener) clazz.newInstance();
            return listener;
        } catch (Exception e) {
            e.printStackTrace();
        }
        throw new RuntimeException("责任链不匹配");
    }


}
